class SoccerMatchController {

    def index = { redirect(action: "list", params: params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def list = {
        params.max = Math.min(params.max ? params.max.toInteger() : 10,  100)
        [soccerMatchInstanceList: SoccerMatch.list(params), soccerMatchInstanceTotal: SoccerMatch.count()]
    }

    def create = {
        def soccerMatchInstance = new SoccerMatch()
        soccerMatchInstance.properties = params
        return [soccerMatchInstance: soccerMatchInstance]
    }

    def save = {
        def soccerMatchInstance = new SoccerMatch(params)
        if (!soccerMatchInstance.hasErrors() && soccerMatchInstance.save()) {
            flash.message = "soccerMatch.created"
            flash.args = [soccerMatchInstance.id]
            flash.defaultMessage = "SoccerMatch ${soccerMatchInstance.id} created"
            redirect(action: "show", id: soccerMatchInstance.id)
        }
        else {
            render(view: "create", model: [soccerMatchInstance: soccerMatchInstance])
        }
    }

    def show = {
        def soccerMatchInstance = SoccerMatch.get(params.id)
        if (!soccerMatchInstance) {
            flash.message = "soccerMatch.not.found"
            flash.args = [params.id]
            flash.defaultMessage = "SoccerMatch not found with id ${params.id}"
            redirect(action: "list")
        }
        else {
            return [soccerMatchInstance: soccerMatchInstance]
        }
    }

    def edit = {
        def soccerMatchInstance = SoccerMatch.get(params.id)
        if (!soccerMatchInstance) {
            flash.message = "soccerMatch.not.found"
            flash.args = [params.id]
            flash.defaultMessage = "SoccerMatch not found with id ${params.id}"
            redirect(action: "list")
        }
        else {
            return [soccerMatchInstance: soccerMatchInstance]
        }
    }

    def update = {
        def soccerMatchInstance = SoccerMatch.get(params.id)
        if (soccerMatchInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (soccerMatchInstance.version > version) {
                    
                    soccerMatchInstance.errors.rejectValue("version", "soccerMatch.optimistic.locking.failure", "Another user has updated this SoccerMatch while you were editing")
                    render(view: "edit", model: [soccerMatchInstance: soccerMatchInstance])
                    return
                }
            }
            soccerMatchInstance.properties = params
            if (!soccerMatchInstance.hasErrors() && soccerMatchInstance.save()) {
                flash.message = "soccerMatch.updated"
                flash.args = [params.id]
                flash.defaultMessage = "SoccerMatch ${params.id} updated"
                redirect(action: "show", id: soccerMatchInstance.id)
            }
            else {
                render(view: "edit", model: [soccerMatchInstance: soccerMatchInstance])
            }
        }
        else {
            flash.message = "soccerMatch.not.found"
            flash.args = [params.id]
            flash.defaultMessage = "SoccerMatch not found with id ${params.id}"
            redirect(action: "edit", id: params.id)
        }
    }

    def delete = {
        def soccerMatchInstance = SoccerMatch.get(params.id)
        if (soccerMatchInstance) {
            try {
                soccerMatchInstance.delete()
                flash.message = "soccerMatch.deleted"
                flash.args = [params.id]
                flash.defaultMessage = "SoccerMatch ${params.id} deleted"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "soccerMatch.not.deleted"
                flash.args = [params.id]
                flash.defaultMessage = "SoccerMatch ${params.id} could not be deleted"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "soccerMatch.not.found"
            flash.args = [params.id]
            flash.defaultMessage = "SoccerMatch not found with id ${params.id}"
            redirect(action: "list")
        }
    }
}
